package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.BlackListMapper;
import com.tanhua.dubbo.mappers.UserInfoMapper;
import com.tanhua.model.domain.BlackList;
import com.tanhua.model.domain.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
@DubboService
public class BlackListImpl implements BlackListApi{
    @Autowired
    private BlackListMapper blackListMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 展示黑名单列表
     * @param userId
     * @param page
     * @param pagesize
     * @return
     */
    @Override
    public Page<UserInfo> backlist(Long userId, int page, int pagesize) {
        //分页器
        Page pages = new Page(page,pagesize);
        return userInfoMapper.findBackList(pages,userId);
    }

    /**
     * 通过当前用户删除黑名单中指定的黑名单用户
     * @param userId
     * @param uid
     */
    @Override
    public void blackByIdDelete(Long userId, Long uid) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        //判断当前用户是否
        queryWrapper.eq("user_id",userId);
        //判断黑名单中的id是否是有你删除的id
        queryWrapper.eq("black_user_id",uid);
        blackListMapper.delete(queryWrapper);
    }
}
